/**
 * iterator 遍历器
 */

Array.prototype.values = function () {
    let i = 0;
    let items = this;
    return {
        next() {
            const done = i > items.length;
            const value = done ? undefined : items[i++];
            return {
                value, done
            }
        }
    }
}

const colors = ['pink', 'lightblue', 'cyan'];
for (const color of colors) {
    console.log(color);
}

const iterator = colors[Symbol.iterator]();
console.log(iterator.next());
console.log(colors.entries());
const entry = colors.entries();
console.log(entry.next());

const key = colors.keys();
console.log(key.next());

const values = colors.values();
console.log(values.next());